package com.chushouya.order.dao.repository;


import com.general.framework.core.lang.Longs;
import com.general.framework.data.mybatis.BaseRepository;
import com.chushouya.order.dao.entity.OrderExtendEntity;
import com.chushouya.order.dao.mapper.OrderExtendEntityMapper;
import com.chushouya.order.dto.admin.orderextend.OrderExtendQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

/**
 * 订单Repository
 */
@Repository
@Slf4j
public class OrderExtendRepository extends BaseRepository<OrderExtendEntityMapper, OrderExtendEntity, Long> {

    public OrderExtendEntity selectByOrderId(Long orderId) {
        Example example = this.buildExample();
        example.and().andEqualTo("orderId", orderId);
        return this.selectFirstOneByExample(example);
    }

    public OrderExtendEntity selectOne(OrderExtendQuery query) {
        return this.selectFirstOneByExample(this.buildExample(query));
    }

    private Example buildExample(OrderExtendQuery query) {
        Example example = buildExample();
        if (Longs.notNullAndZero(query.getOrderId())) {
            example.and().andEqualTo("orderId", query.getOrderId());
        }
        return example;
    }
}
